package com.lm;

import com.graphics.ImageIdentity;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 *
 * @author Sajarwo Anggai
 */
public class Tile {

    private ImageIdentity imageIdentity;
    private int pos;
    private BufferedImage tileImage;
    int tileX, tileY;

    public Tile(ImageIdentity imageIdentity, int pos) {
        this.imageIdentity = imageIdentity;
        this.pos = pos;
        refresh();
    }

    public void setImageIdentity(ImageIdentity imageIdentity) {
        this.imageIdentity = imageIdentity;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }

    public void refresh() {
        this.tileImage = (BufferedImage) imageIdentity.getImages().get(pos);
    }

    public ImageIdentity getImageIdentity() {
        return imageIdentity;
    }

    public int getPos() {
        return pos;
    }

    public void draw(Graphics2D g2d, int x, int y, int w, int h) {
        tileX = WorkSpace.tilesToPixels(x, w);
        tileY = WorkSpace.tilesToPixels(y, h);
        g2d.drawImage(tileImage.getSubimage(0, 0, w, h), tileX, tileY, null);
    }
}
